package com.sevenmall.productservice.util;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class Gen {
    public static void main(String[] args) {
        AutoGenerator mpg = new AutoGenerator();
        //选择freemarker引擎,默认Veloctiy
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());

        //数据源配置，通过该配置，指定需要生成代码的具体数据库
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://114.55.24.118:3306/sevenmall?useUnicode=true&characterEncoding=utf8");
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("sevenmall");
        dsc.setPassword("sevenmall");
        mpg.setDataSource(dsc);

        //数据库表配置，通过该配置，可指定需要生成哪些表或者排除哪些表
        StrategyConfig strategy = new StrategyConfig();
        strategy.setTablePrefix("sevenmall_");
        strategy.setInclude(new String[]{
                "sevenmall_brand",
                "sevenmall_category",
                "sevenmall_comment",
                "sevenmall_product",
                "sevenmall_parameter",
                "sevenmall_specification",
                "sevenmall_sku"}); //需要生成的表
        mpg.setStrategy(strategy);

        //包名配置，通过该配置，指定生成代码的包路径
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.sevenmall.productservice");
        pc.setEntity("pojo");
        pc.setMapper("mapper");
        pc.setXml("mapper.mapping");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setController("controller");
        mpg.setPackageInfo(pc);

        //全局策略配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOpen(false);
        gc.setOutputDir("D://Code/SevenMall/product-service/src/main/java");//生成文件的输出目录,默认值D盘根目录
        gc.setFileOverride(false);//是否覆盖同名文件,默认值false
        gc.setOpen(true);//是否打开输出目录,默认值true
        gc.setAuthor("Yesi");//开发人员
        gc.setActiveRecord(true);// 不需要ActiveRecord特性的请改为false
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(false);// XML columList
        gc.setServiceName("%sService");
        mpg.setGlobalConfig(gc);

        //执行
        mpg.execute();
    }
}
